<!DOCTYPE html>
 <html>
 <head>
     <meta charset="utf-8">
     <title>layui</title>
     <meta name="renderer" content="webkit">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
     <link rel="stylesheet" href="__ADMIN__/lib/layui-v2.5.5/css/layui.css" media="all">
     <link rel="stylesheet" href="__ADMIN__/css/public.css" media="all">
     <style>
         body {
             background-color: #ffffff;
         }
     </style>
 </head>
 <body>
 <div class="layui-form layuimini-form" lay-filter="ruleForm">
     {:token('mykey')}
     <div class="layui-form-item">
         <label class="layui-form-label required">名称</label>
         <div class="layui-input-block">
             <input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="" class="layui-input">
         </div>
     </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">父级规则</label>
        <div class="layui-input-inline">
            <input type="text" name="fid" value="" class="layui-input layui-disabled" disabled>
        </div>
        <div class="layui-form-mid layui-word-aux">父级规则，不可修改</div>
    </div>
     <div class="layui-form-item">
         <label class="layui-form-label required">规则</label>
         <div class="layui-input-block">
             <input type="text" name="url" placeholder="请输入规则" class="layui-input">
         </div>
     </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">hash值</label>
        <div class="layui-input-block">
            <input type="text" name="hash" placeholder="请输入hash值" class="layui-input">
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">打开窗口方式</label>
        <div class="layui-input-inline">
          <select name="target" lay-verify="required">
            <option value="_self">本身 _self</option>
            <option value="_blank">新窗口 _blank</option>
          </select>
        </div>
      </div>
    <div class="layui-form-item">
         <label class="layui-form-label required">菜单</label>
         <div class="layui-input-block">
            <input type="checkbox" name="is_menu" lay-skin="switch" lay-text="是|否" checked>
         </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">图标</label>
        <div class="layui-input-block">
            <input type="text" name="icon" placeholder="请输入图标" class="layui-input" value="layui-icon layui-icon-layer">
        </div>
    </div>
    <div class="layui-form-item">
            <label class="layui-form-label required">权重</label>
            <div class="layui-input-inline">
                <input type="number" min="0" max="200" name="sort" lay-verify="required" lay-reqtext="权重不能为空" value="200" class="layui-input">
            </div>
        </div>
     <div class="layui-form-item">
         <label class="layui-form-label">状态</label>
         <div class="layui-input-block">
             <input type="checkbox" name="status" lay-skin="switch" lay-text="正常|禁用" checked>
         </div>
     </div>
     <div class="layui-form-item">
         <div class="layui-input-block">
             <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
         </div>
     </div>
 </div>
 </div>
 <script src="__ADMIN__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
 <script>
     layui.use(['form'], function () {
         var form = layui.form,
             layer = layui.layer,
             $ = layui.jquery;

        var collectionId = parent.$('#hideCollectionId').val();
        form.val('ruleForm', {
            'fid': collectionId
        })
         //监听提交
         form.on('submit(saveBtn)', function (data) {
             const param = data.field;
             if(param.status && param.status == 'on') {
                 param.status = 1;
             } else {
                 param.status = 0;
             }
             if(param.is_menu && param.is_menu == 'on') {
                 param.is_menu = 1;
             } else {
                 param.is_menu = 0;
             }
             $.ajax({
                 url: '/admin/menu/add',
                 data: param,
                 method: 'post',
                 success: function (res) {
                     layer.msg(res.msg, {
                         icon: res.code > 0 ? 1 : 0,
                         time: 500,
                         shade: 0.1
                     }, function () {
                        if(res.code > 0)
                            closeThis(true)
                     });
                 }
             })
             return false;
         });
 
         function closeThis(re = false)
         {
             var iframeIndex = parent.layer.getFrameIndex(window.name);
             if(re)
                 parent.$('#isReload').val('yes');
             parent.layer.close(iframeIndex);
         }
     });
 </script>
 </body>
 </html>